#!/usr/bin/env python
# coding=utf-8
# 框架默认加载页面

import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp import util
import crondb
import datetimetool
import time
import common

class MainHandler(webapp.RequestHandler):
	def get(self):
		user = users.get_current_user()
		if user:
			if users.is_current_user_admin():
				self.response.headers["Content-Type"] = "text/html; charset=utf-8"
				self.response.out.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Main - Beikx Cron</title>
    <link href="css/general.css" rel="stylesheet" type="text/css" />
    <link href="css/main.css" rel="stylesheet" type="text/css" />
	</head>
<body>
	<div>
		<h1>
			<span class="action-span1"><a href="main">Beikx Cron</a> </span>
		</h1>
		<div style="clear: both" />
		<div class="list-div">
			<table cellspacing="1" cellpadding="3">
				<tr>
					<th colspan="4" class="group-title">
						Status</th>
				</tr>
				<tr>
					<td style="width: 20%;">
						Server Time:
					</td>
					<td style="width: 30%;">
						""")
				now = datetimetool.getCNnow()
				self.response.out.write("(UTD+8)Beijing Time: %s" % str(now))
				self.response.out.write("<br/>Server Time: %s" % str(datetimetool.getNow()))
				self.response.out.write("""</td>
					<td style="width: 20%;">
						Version:
					</td>
					<td style="width: 30%;">""")
				self.response.out.write(common.getVersion())
				self.response.out.write("""</td>
				</tr>
				<tr>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;</td>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;</td>
				</tr>
			</table>
		</div>
		<br />
		<div class="list-div">
			<table cellspacing="1" cellpadding="3">
				<tr>
					<th colspan="4" class="group-title">
						&nbsp;</th>
				</tr>
				<tr>
					<td style="width: 20%;">
						&nbsp;
					</td>
					<td style="width: 30%;">
						&nbsp;</td>
					<td style="width: 20%;">
						&nbsp;
					</td>
					<td style="width: 30%;">
						&nbsp;</td>
				</tr>
				<tr>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;</td>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;</td>
				</tr>
			</table>
		</div>
		<br />
		<div id="footer">
			<br />""")
				self.response.out.write(common.getCopyRight())
				self.response.out.write("""</div>
	</div>
</body>
</html>
""")
			else:
				common.writeNoPermissionMessage(self)
		else:
			self.redirect(users.create_login_url(self.request.uri))

def main():
	application = webapp.WSGIApplication([('/main', MainHandler)],
		debug=True)
	util.run_wsgi_app(application)


if __name__ == '__main__':
	main()
